<template>
  <div class="app-container">
    <div class="view-title">app信息</div>
    <div class="app_information_title">
      <div class="app_title">{{ appInfo.app_filings }}</div>
      <div>
        <el-input
          v-model="appFilingsValue"
          placeholder="请输入APP备案信息"
        ></el-input>
      </div>
    </div>

    <div class="app_information_title">
      <div class="app_title">{{ appInfo.html_filings }}</div>
      <div>
        <el-input
          v-model="htmlFilingsValue"
          placeholder="请输入网站备案信息"
        ></el-input>
      </div>
    </div>

    <div class="app_information_title">
      <div class="app_title">{{ appInfo.privacy_agreement }}</div>
      <div>
        <el-input
          type="textarea"
          v-model="privacyAgreementValue"
          placeholder="请输入隐私协议"
        ></el-input>
      </div>
    </div>

    <div class="app_information_title">
      <div class="app_title">{{ appInfo.user_agreement }}</div>
      <div>
        <el-input
          type="textarea"
          v-model="userAgreementValue"
          placeholder="请输入用户协议"
        ></el-input>
      </div>
    </div>

    <div class="app_information_title">
      <div class="app_title">首页消息</div>
      <div>
        <!-- <el-input type="textarea" v-model="userAgreementValue" placeholder="请输入用户协议"></el-input> -->
        <tinymce
          ref="myEditor"
          @input="input"
          :value="indexContentValue"
        ></tinymce>
      </div>
    </div>

    <div class="app_information_title">
      <div class="app_title">是否展示首页消息</div>
      <div>
        <!-- <el-input type="textarea" v-model="userAgreementValue" placeholder="请输入用户协议"></el-input> -->
        <el-switch
          v-model="indexContentStatusValue"
          active-color="#13ce66"
          inactive-color="#ff4949"
        >
        </el-switch>
      </div>
    </div>

    <div>
      <div>
        <el-button
          type="primary"
          @click="handleSubmit"
          v-permission="['appInformation:save']"
          >保存</el-button
        >
      </div>
    </div>
  </div>
</template>
<script>
import { getAppInfoInfo, updateAppInfo } from "@/api/appInformation";
import tinymce from "@/components/Tinymce/index.vue";
export default {
  components: {
    tinymce,
  },
  data() {
    return {
      appInfo: {},
      appFilingsValue: "",
      htmlFilingsValue: "",
      privacyAgreementValue: "",
      userAgreementValue: "",
      indexContentStatusValue: false,
      indexContentValue: "",
    };
  },
  mounted() {
    this.getAppInfoInfo();
  },
  methods: {
    // 查询app信息
    getAppInfoInfo() {
      getAppInfoInfo(1).then((res) => {
        if (res.code == 1) {
          this.appInfo = res.data;
        } else {
          this.$message.error(res.msg);
          return;
        }
      });
    },

    // 修改app信息
    updateAppInfo() {
      updateAppInfo({
        id: 1,
        version: this.appFilingsValue,
        user_agreement: this.userAgreementValue,
        privacy_agreement: this.privacyAgreementValue,
        app_filings: this.appFilingsValue,
        html_filings: this.htmlFilingsValue,
        index_content: this.indexContentValue,
        index_content_status: this.indexContentStatusValue,
      }).then((res) => {});
    },

    // 保存
    handleSubmit() {
      this.updateAppInfo();
    },

    input(val) {
      this.indexContentValue = val;
    },
  },
};
</script>
<style lang="scss" scoped>
.app-container {
  .app_information_title {
    padding: 20px 0;

    .app_title {
      padding-bottom: 10px;
    }
  }
}
</style>
